package com.kathryn.LG;

import java.util.ArrayList;
import java.util.List;

import com.demo.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class SpecialAdapter extends BaseAdapter {
	private ArrayList<MyList> serialList;
	private Context context;
	private int[] item;
	View view;
	private List<GalleryItem> galleryitems;

	public SpecialAdapter(Context context, List<GalleryItem> galleryitems,
			ArrayList<MyList> dataObjects, int[] item) {
		super();
		this.context = context;
		this.serialList = dataObjects;
		this.item = item;
		this.galleryitems = galleryitems;
	}

	@Override
	public int getCount() {
		return serialList.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		view = LayoutInflater.from(parent.getContext()).inflate(
				R.layout.listview_item, null);
		for (int i = 0; i < item.length; i++) {
			TextView title = (TextView) view.findViewById(item[i]);
			title.setText(serialList.get(position).getSerialName());
			LinearLayout ll = (LinearLayout) view.findViewById(R.id.ll);
			ll.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Toast.makeText(context, "listview  position "+position, 0).show();
					
				}
			});
		}
		GalleryItem items = this.galleryitems.get(position);
		GalleryItem gallery = (GalleryItem) view.findViewById(R.id.item_gallery);
		gallery.setAdapter(items.adapter);
		/*gallery.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				
				Toast.makeText(context, "gallery position"+arg2, 0).show();
			}
		});*/
		/**
		 * Sets the currently selected item. To support accessibility subclasses that override this method
		 *  must invoke the overriden super method first.
		 */
		gallery.setSelection(2);
		return view;
	}

}
